<style lang="less">
    .card_style {
        height: 100%;
        width: 100%;
        overflow: hidden;
        .ivu-card-body {
            padding: 0px;
        }
    }

    .page_style {
        margin-top: 10px;
        text-align: right;
    }

    .bench_search {
        margin-bottom: 10px;
    }

    .nopadding .ivu-table-cell {
        padding: 0px 0px;
    }

    .item1 {
        height: 42px;
        line-height: 40px;
    }
</style>
<template>
    <div>
        <Form :label-width="120" inline>
            <Form-item label="统计年份:">
                <Input style="width: 100px" v-model="queryParam.sssa0001"/>
            </Form-item>
            <Row class="button_row">
                <span style="float: left;">
                 <Button type="primary" @click="createModel"><Icon type="ios-add"/>创建</Button>
                </span>
                <span style="float: right;">
                      <Button type="primary" @click="searchQuery"><Icon type="ios-search"/> 查询</Button>
                <Button type="primary" class="button_item_left" @click="searchReset"><Icon type="ios-refresh"></Icon>重置</Button>
                </span>
            </Row>
        </Form>
        <Modal v-model="modalShow" :title="title" :mask-closable="false" width="500">
            <Form :model="formItem" :label-width="150" ref="ruleValidate" :rules="ruleValidate">
                <FormItem label="年度:" prop="sssa0001">
                    <Input :min="0" v-model="formItem.sssa0001" style="width: 200px;" v-bind:disabled="disable"
                           placeholder="年度"></Input>
                </FormItem>
                <FormItem label="行政区划:" prop="sssa0002">
                    <Input :min="0" v-model="formItem.sssa0002" style="width: 200px;" disabled
                           placeholder="行政区划"></Input>
                </FormItem>
                <FormItem label="社会月平均工资:" prop="sssa0003">
                    <Input :min="0" v-model="formItem.sssa0003" style="width: 200px;" v-bind:disabled="disable"
                           placeholder="社会月平均工资"></Input>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="info" v-if="type==='1' && type !== '3'" @click="addOk('ruleValidate')">添加</Button>
                <Button type="info" v-if="type==='2' && type !== '3'" @click="updateOk('ruleValidate')">保存</Button>
                <Button type="default" @click="closeModel">关闭</Button>
            </div>
        </Modal>
        <div class="table_div">
            <Table :columns="columns1" :data="tableData">
                <template slot-scope="{ row }" slot="action">
                    <Button type="info" v-if="row.id != null" size="small" style="margin-right: 5px"
                            @click="updateModal(row)">编辑
                    </Button>
                    <Button type="error" v-if="row.id != null" size="small" style="margin-right: 5px"
                            @click="remove(row)">删除
                    </Button>
                    <Button type="success" v-if="row.id != null" size="small" style="margin-right: 5px"
                            @click="showModal(row)">详情
                    </Button>
                </template>
            </Table>
            <Page :total="dataCount" :page-size="pageSize" @on-change="handleTableChange" :current="pageNo" show-total
                  class="paging"></Page>
        </div>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import Ss01001Tag from '@/components/system/ss01001-select'

    export default {
        mixins: [CommonMixin],
        data() {
            return {
                ruleValidate: {
                    // ccsa0001: [
                    //     { required: true,  type: 'string', message: '请选择区划', trigger: 'change' }
                    // ],
                    sssa0001: [
                        {
                            required: true,
                            message: '请输入年度'
                        },
                        {
                            type: 'number',
                            message: '输入的类型为数字',
                            transform(value) {
                                return Number(value);
                            }
                        }
                    ],
                    sssa0003: [
                        {
                            required: true,
                            message: '请输入社会月平均工资'
                        },
                        {
                            type: 'number',
                            message: '输入的类型为数字',
                            transform(value) {
                                return Number(value);
                            }
                        }
                    ],
                },
                type: '',
                title: '',
                sel_xqval: '',
                mode: true,
                statusLevel: '',
                disable: false,
                formItem: {
                    id: '',
                    sssa0001: '',
                    sssa0003: '',
                    sssa0002: '辽宁省沈阳市',

                },
                modalShow: false,
                // 初始化信息总条数
                dataCount: 0,
                // 每页显示多少条
                pageSize: 5,
                queryParam: {},
                url: {
                    list: "/api/ac/subsistence/ss09001Service/getPageList",
                },
                columns1: [
                    // {
                    //     title: '序号',
                    //     key: 'id',
                    //     align: 'center',
                    //     width: '100'
                    // },
                    {
                        title: '统计年度',
                        key: 'sssa0001',
                        align: 'center',
                        width: '200'
                    },
                    {
                        title: '行政区划',
                        align: 'center',
                        width: '200',
                        key: 'sssa0002'
                    },
                    {
                        title: '社会月平均工资',
                        align: 'center',
                        width: '300',
                        key: 'sssa0003'
                    }
                    , {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        slot: 'action',
                        className: 'nopadding',
                        minWidth: 100
                    }
                ],
                data: []
            }
        },
        methods: {
            handleSuccess(res, file) {
                if (res.errcode === 0) {
                    if (res.data.errorcode === 0) {
                        this.$refs.upload.clearFiles();
                        this.dialoLead = false;
                        this.$Message.success("数据导入成功！");
                        this.loadData(1);
                    } else {
                        this.$Message.error(res.data.msg);
                        this.$refs.upload.clearFiles()
                    }

                }

            },
            handleError(error, file) {
                this.$Message.error("数据导入失败！")
            },
            // 删除
            remove(item) {
                this.$Modal.confirm({
                    title: '确定删除该条数据吗？',
                    onOk: () => {
                        var dataParam = {
                            id: item.id
                        }
                        postAction('/api/ac/subsistence/ss09001Service/delete', dataParam).then((res) => {
                            this.loadData()
                            this.$Notice.success({title: '删除成功', desc: ''})
                            this.modalShow = false
                        }).finally(() => {

                        })
                    }
                })
            },
            closeModel() {
                this.modalShow = false
            },
            //新增事件
            addOk(name) {
                this.formItem.ccsa0001 = this.formItem.bindXq;
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let dataParam = {
                            sssa0001: this.formItem.sssa0001,
                            sssa0003: this.formItem.sssa0003,
                        }
                        postAction('/api/ac/subsistence/ss09001Service/insert', dataParam).then((res) => {
                            if (res.data.data.errcode === 0) {
                                this.modalShow = false
                                this.$Message.success("新增成功！")
                                this.loadData(1)
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '请输入不为空的项!', desc: '请输入不为空的项!'})
                    }
                });

            },
            updateOk(name) {
                this.formItem.ccsa0001 = this.formItem.bindXq;
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let dataParam = {
                            id: this.formItem.id,
                            sssa0001: this.formItem.sssa0001,
                            sssa0003: this.formItem.sssa0003,
                        }
                        postAction('/api/ac/subsistence/ss09001Service/update', dataParam).then((res) => {
                            if (res.data.data.errcode === 0) {
                                this.modalShow = false
                                this.$Message.success("编辑成功！")
                                this.loadData(1)
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '请输入不为空的项!', desc: '请输入不为空的项!'})
                    }
                });

            },
            //新增扶贫人口事件
            createModel() {
                var date = new Date();
                this.modalShow = true
                this.formItem.id = ''
                this.formItem.sssa0001 = date.getFullYear();
                this.formItem.sssa0003 = ''
                this.type = '1'
                this.title = '新增'
                this.disable = false
            },
            showModal(row) {
                this.modalShow = true
                this.type = '3'
                this.title = '详情'
                this.formItem = row
                this.disable = true
            },
            updateModal(row) {
                //下拉框选中
                this.modalShow = true
                this.type = '2'
                this.title = '修改'
                this.formItem.id = row.id
                this.formItem.sssa0001 = row.sssa0001
                this.formItem.sssa0003 = row.sssa0003
                this.formItem = row
                this.disable = false
            },
            //获取数据
            changePage(pageNo) {
                //页面翻页事件
                this.data = this.loadData(pageNo);
            }
        },
        created() {
            // 默认请求第一页列表
            this.loadData();
        }

    }
</script>

<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }
</style>
